package com.meet.controller;

import com.meet.bizservice.SocialService;
import com.meet.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Min;

@RestController
@RequestMapping("/messages")
@CrossOrigin
@Validated
public class MeetPrivateMessageController {

    @Autowired
    private SocialService socialService;

    @PostMapping("/private")
    public Result<?> sendPrivateMessage(@RequestBody @Validated PrivateMessageRequest request) {
        return socialService.sendPrivateMessage(request.getReceiverId(), request.getContent());
    }

    @GetMapping("/list")
    public Result<?> getMessagesList(@RequestParam(defaultValue = "1") @Min(1) int page,
                                     @RequestParam(defaultValue = "10") @Min(1) int limit) {
        return socialService.getMessagesList(page, limit);
    }

    // Request DTO
    public static class PrivateMessageRequest {
        @NotBlank(message = "接收者ID不能为空")
        private String receiverId;

        @NotBlank(message = "消息内容不能为空")
        private String content;

        // Getters and Setters
        public String getReceiverId() {
            return receiverId;
        }

        public void setReceiverId(String receiverId) {
            this.receiverId = receiverId;
        }

        public String getContent() {
            return content;
        }

        public void setContent(String content) {
            this.content = content;
        }
    }
}
